package com.compass.doctor.ui.home.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.LayoutDrugItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.ext.gone
import com.compass.framework.ext.onClick
import com.compass.framework.ext.visible
import com.compass.framework.model.DrugItem
import com.compass.framework.utils.ViewUtils
import com.compass.framework.utils.dpToPx

/**
 * Description： 药品信息item
 * Date:2023/12/7 10:40
 */
class DrugItemAdapter constructor(private var itemType: Int) : BaseRecyclerViewAdapter<DrugItem, LayoutDrugItemBinding>() {


    private lateinit var onAppendDrugClick:OnCustomButtonClick

    fun setBottomCallBack(onBottomClick: OnCustomButtonClick) {
        this.onAppendDrugClick = onBottomClick
    }
    //1.药房进入的item 2、处方添加药品的item
    override fun getDefItemViewType(position: Int): Int {
        return itemType
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutDrugItemBinding>,
        item: DrugItem?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            if (position==getData().size-1) viewLine.visibility= View.GONE else viewLine.visibility= View.VISIBLE
            tvTitle.text = item.name
            ViewUtils.setClipViewCornerRadius(imgDoctorHead, dpToPx(5))
            tvPrice.text =item.price.toString()
            tvPackingUnit.text =item.packingUnit

             if (itemType==1)   ivAddDrugs.gone() else   ivAddDrugs.visible()
            ivAddDrugs.onClick {
                if (itemType==1){
                    ivAddDrugs.gone()
                    onAppendDrugClick.onButtonCallBack(position,"common_medicine")
                }else{
                    onAppendDrugClick.onButtonCallBack(position,"prescription")
                }
            }
        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutDrugItemBinding {
        return LayoutDrugItemBinding.inflate(layoutInflater, parent, false)
    }
}